package com.lemonfish.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lemonfish.enumcode.CodeEnum;
import com.lemonfish.pojo.dto.UserDTOLikeSearch;
import com.lemonfish.pojo.entity.Orderlist;
import com.lemonfish.pojo.vo.OrderlistVO;
import com.lemonfish.service.OrderlistService;
import com.lemonfish.util.MyJsonResult;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 订单 相关Controller
 *
 * @author Lemonfish
 * @version 1.0
 * @date 2020-03-14
 * Copyright © Chao Zhang
 */
@Api(tags = {"订单"})
@RestController
@RequestMapping("/orderlist")
@Slf4j
public class OrderlistController extends BaseCrudMappingRestController<Orderlist, OrderlistVO> {
    @Autowired
    private OrderlistService orderlistService;

    /**
     * 获取页面数据
     *
     * @param curPage 当前页码
     * @param size    每页条数
     * @param order   排序
     * @param column  排序的字段
     * @return
     */
    @GetMapping("/{curPage}/{size}")
    public MyJsonResult getUserList(@PathVariable("curPage") long curPage, @PathVariable("size") long size, @RequestParam("order") String order, @RequestParam("orderCol") String column) {
        IPage<Orderlist> userList = orderlistService.getOrderList(curPage, size, order, column);
        if (userList != null) {
            return MyJsonResult.success(userList);
        } else {
            return MyJsonResult.fail(CodeEnum.FAIL_NOT_FOUND);
        }
    }


    /**
     * 模糊查询
     *
     * @param content
     * @return
     */
    @PostMapping("/likeSearch/{curPage}/{pageSize}")
    public MyJsonResult likeSearch(@RequestBody UserDTOLikeSearch content,
                                   @PathVariable("curPage") long curPage,
                                   @PathVariable("pageSize") long pageSize,
                                   @RequestParam("order") String order,
                                   @RequestParam("orderCol") String column) {
        IPage<Orderlist> result = orderlistService.getAllByLike(content, curPage, pageSize, order, column);
        return MyJsonResult.success(result);
    }
}
